<?php

date_default_timezone_set('PRC'); // 切换到中国的时间
require_once('../log.php');
/** 
* @name Api接口demo（php版）
* @desc 本接口列表，只是用于系统处理机器人行为
* 一分钟执行一次，给符合条件的机器人发送

*/

$dataing = date('Y-m-d H:i:s',time());
$hm_time = substr($dataing,11,5);

function again($index){
	$index = $index + 1;
	if($index > 2)
	{
		$index = 0;
	}

	$fp = fsockopen("192.168.0.109","90", $errno, $errmsg);
	$request = "GET /timeTask/crontab.php?index=".$index;

	$request = $request."\r\n\r\n";

	LOGINFO($request,"request");
	fputs($fp, $request);        //这里的第二个参数是HTTP协议中规定的请求头

	fclose($fp);
}

//执行云发单任务
function botsendAction(){
	$fp = fsockopen("192.168.0.109","90", $errno, $errmsg);
	$request = "GET /timeTask/botsendAction.php";

	$request = $request."\r\n\r\n";

	LOGINFO($request,"request");
	fputs($fp, $request);        //这里的第二个参数是HTTP协议中规定的请求头

	fclose($fp);
}

//执行更新淘宝订单任务
function updateTaobaoGood(){
	$fp = fsockopen("192.168.0.109","90", $errno, $errmsg);
	$request = "GET /timeTask/getTaobaoGood.php";

	$request = $request."\r\n\r\n";
	fputs($fp, $request);        //这里的第二个参数是HTTP协议中规定的请求头

	fclose($fp);
}

//执行更新京东订单任务
function updateJdGood(){
	$fp = fsockopen("192.168.0.109","90", $errno, $errmsg);
	$request = "GET /timeTask/getJdGood.php";

	$request = $request."\r\n\r\n";
	fputs($fp, $request);        //这里的第二个参数是HTTP协议中规定的请求头

	fclose($fp);
}

//执行更新拼多多订单任务
function updatePddGood(){
	$fp = fsockopen("192.168.0.109","90", $errno, $errmsg);
	$request = "GET /timeTask/getPddGood.php";

	$request = $request."\r\n\r\n";
	fputs($fp, $request);        //这里的第二个参数是HTTP协议中规定的请求头

	fclose($fp);
}

//执行清除图片任务
function removeImgAction(){
	$fp = fsockopen("192.168.0.109","90", $errno, $errmsg);
	$request = "GET /timeTask/removeImg.php";

	$request = $request."\r\n\r\n";
	fputs($fp, $request);        //这里的第二个参数是HTTP协议中规定的请求头

	fclose($fp);
}



$index = $_GET['index'];
$start = $_GET['start'];
if($start == 1)
{
	again(0);
	var_dump("正在启动成功");
}
else{
	sleep(29);
	again($index);
	if($index == 2)
	{
		botsendAction();
		//updateTaobaoGood();
		if($hm_time == "00:00"){
			LOGINFO("更新宝贝");
			updateTaobaoGood();
			removeImgAction();
		}
	}
}


?>